-
-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(functions): expand xor function and add exclusive option for or functionality #2616
base: develop
Are you sure you want to change the base?
feat(functions): expand xor function and add exclusive option for or functionality #2616
Conversation
…re/expand-xor-add-or
This has now been merged with stoplightio:develop containing prior "xor" PR #2614, "feat(rulesets): add multiple xor", and rest of spectral develop branch. |
Define exclusive as optional. Co-authored-by: Brenda Rearden <[email protected]>
Safely handle any type of exclusive argument, not just boolean or null values. Co-authored-by: Brenda Rearden <[email protected]>
Hi @cuttingclyde, I appreciate that this started as an expand of XOR functionality and evolved as #2614 was merged. XOR - as in exclusive or has an expected behaviour within programming languages. The remaining part of this proposal adds a It would be cleaner, more maintainable, and more usable to introduce a new or core function which offers this behaviour rather than misusing XOR and effectively negating the 'X' part. Could you rework this and instead add a new core OR function? |
That’s my recollection of what I had done, was also create the OR function in that same branch. I’ll try to look at it later today.
- Clyde
On Dec 17, 2024, at 9:34 AM, Frank Kilcommins notifications-at-github.com |GitHub-cuttingus| ***@***.***> wrote:
Hi @cuttingclyde<https://github.com/cuttingclyde>,
I appreciate that this started as an expand of XOR functionality and evolved as #2614<#2614> was merged.
XOR - as in exclusive or has an expected behaviour within programming languages. The remaining part of this proposal adds a exclusive boolean property (defaulting to true) which if set to false introduces non-exclusive behaviour so that the function can work as OR type behaviour.
It would be cleaner, more maintainable, and more usable to introduce a new or core function which offers this behaviour rather than misusing XOR and effectively negating the 'X' part.
Could you rework this and instead add a new core OR function?
—
Reply to this email directly, view it on GitHub<#2616 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACUFXTYNGDHJ3FWS7HZMIAD2GBABFAVCNFSM6AAAAABRXVTKGCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNBYG43TKMZVHA>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Oh, I see what you mean.
I had done that (separate OR function) in an earlier commit, then reduced it to the combined version in the latest. I’ll look back at the earlier commits and restore the OR one.
- Clyde
On Dec 17, 2024, at 9:34 AM, Frank Kilcommins notifications-at-github.com |GitHub-cuttingus| ***@***.***> wrote:
Hi @cuttingclyde<https://github.com/cuttingclyde>,
I appreciate that this started as an expand of XOR functionality and evolved as #2614<#2614> was merged.
XOR - as in exclusive or has an expected behaviour within programming languages. The remaining part of this proposal adds a exclusive boolean property (defaulting to true) which if set to false introduces non-exclusive behaviour so that the function can work as OR type behaviour.
It would be cleaner, more maintainable, and more usable to introduce a new or core function which offers this behaviour rather than misusing XOR and effectively negating the 'X' part.
Could you rework this and instead add a new core OR function?
—
Reply to this email directly, view it on GitHub<#2616 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACUFXTYNGDHJ3FWS7HZMIAD2GBABFAVCNFSM6AAAAABRXVTKGCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNBYG43TKMZVHA>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Fixes #2396 . This has now been merged with stoplightio:develop containing prior "xor" PR #2614.
Checklist
Does this PR introduce a breaking change?
(Just saw JeanArhancet's similar pull request, feat(rulesets): add multiple xor .)
FDX (see below) has extended XOR here to support from 1 to any number of properties. This would match the XOR logical function, that as long as exactly one of the (1 or more) properties is defined, then the rule passes. With just one property defined in the functionOptions,
xor
becomes redundant withdefined
function.Updated error response messages to account for possibility of schema matching any number of properties or schema not matching any of any number of functionOption properties.
Updated functionOptions error messages to show example arrays containing from one to three ("and etc") properties.
Since
then
can take an array which implements AND-ing of rule requirements, this PR also defines and adds anexclusive
(default true) option to XOR function to provide OR behavior.exclusive: false
works just likexor
for requiring at least one matching property, but then permits more than one matching property as valid and satisfying the rule.Updated functions documentation for
xor
changes to allow more than two properties and newexclusive
option to permit multiple matches.Additional context
The Financial Data Exchange (FDX, https://financialdataexchange.org) industry consortium for Open Banking delivers 13 OpenAPI 3.1 files with nearly 17,000 lines, 47 paths, 70 operations and 374 defined schemas, We enforce our FDX API Style Guide using 48 custom spectral rules and 23 overrides over 870 ruleset lines. We wanted to enforce that
type
was defined for each schema, but a schema can get its type in 3 (or 4) ways:type
,$ref
, oroneOf
. (We are not usingallOf
to definetype
.) This was ideal for an unresolved xor rule with propertiestype
,$ref
, oroneOf
. We initially implemented this as a custom function which met our needs, so are now contributing this to the spectral community. Our rule using our customxor
function:Secondly, there is an OR-rule opportunity to ensure that defined schemas contain sufficient documentation, as a style guide requirement. In particular, each schema ought to have its use / purpose described for users, which can be done in any of
title
,summary
, ordescription
fields. This is an ideal place for anor
function, since any one of those can provide the required schema documentation text, but two or three of them is also just as valid (or better!). A similar example (also included in this PR's tests), would be requiring a helpful example for atype: string
schema, which could be provided by any offormat
,example
, orpattern
fields in the API spec, but again more than one is acceptable.